package com.example.module_service.device

import android.os.Bundle
import android.util.Log
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView.VERTICAL
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.example.lib_base.path.RouterPath
import com.example.lib_common.view.entity.PatrolsBeanItem
import com.example.lib_common.view.view.BaseMvvmActivity
import com.example.module_service.R
import com.example.module_service.adapter.PatrolLocationAdapter
import com.example.module_service.databinding.ActivityTaskDetailBinding
import com.example.module_service.viewmodel.ServerViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = RouterPath.PATH_PATROL_IDETAIL_PAGE)
class TaskDetailActivity : BaseMvvmActivity<ActivityTaskDetailBinding>() {


    private val viewModel : ServerViewModel by viewModels()

    @Autowired
    lateinit var tid:String
    val list = mutableListOf<PatrolsBeanItem>()
    val patrolLocationAdapter by lazy{
        PatrolLocationAdapter()
    }
    override fun getLayoutId(): Int {
        return R.layout.activity_task_detail
    }

    override fun initViews() {
        super.initViews()
        ARouter.getInstance().inject(this)
        viewModel.getTaskById(tid.toInt())

        mDataBinding.taskDetailRv.apply {
            adapter = patrolLocationAdapter
            layoutManager = LinearLayoutManager(this@TaskDetailActivity)
            addItemDecoration(DividerItemDecoration(this@TaskDetailActivity, VERTICAL))
        }
    }

    override fun onResume() {
        super.onResume()
        viewModel.getPointById.observe(this){
            Log.i("===",it.toString())
            patrolLocationAdapter.addData(it)
            patrolLocationAdapter.notifyDataSetChanged()
        }

        viewModel.getTasksBId.observe(this){
            mDataBinding.taskDetailName.setText(it.taskName)
            mDataBinding.taskDetailTime.setText(it.patrolTime)
            it.patrolPoints.forEach{
                viewModel.getTaskById(it)
            }
        }
    }

}